package com.peter.framework.service.urlfetch;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.Proxy.Type;

import org.apache.commons.lang.CharEncoding;

public class ProxiedHttpService implements HttpService {

	@Override
	public String getFromUrl(URL url) throws IOException {
		BufferedReader reader = null;
		try {
			Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(
					"proxy.hkcsl.net", 8080));
			URLConnection urlConnection = url.openConnection(proxy);
			reader = new BufferedReader(new InputStreamReader(urlConnection
					.getInputStream(), CharEncoding.UTF_8));
			return reader.readLine();
		} finally {
			if (reader != null) {
				reader.close();
			}
		}
	}

}
